<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
	<link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
<style>
input.error{
	border:1px solid red;
}
span.error{
	padding-top:10px;
	color: #f00;
	font-size:12px;
}
</style>
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>更换客服账号</h5>
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal" id="form">     
			                <div class="form-group">
			                    <label class="col-sm-2 control-label">客服名称：</label>
                                <div class="col-sm-6">
                                    <div style="font-size:14px; width:200px; height:35px; line-height:35px;">{$memberInfo.user_name}</div>
                                </div>
			                </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">客服手机号码：</label>
                                <div class="col-sm-6">
                                    <div style="font-size:14px; width:200px; height:35px; line-height:35px;">{$memberInfo.phone}</div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">新客服手机号：</label>
                                <div class="col-sm-6">
                                    <input type="text" style="width:61%;" class="form-control" name="new_phone" id="new_phone">
                                </div>
                            </div>

			                <div class="form-group">
			                    <label class="col-sm-2 control-label">短信验证码：</label>
			                    <div class="col-sm-6">
			                    <input type="text" class="form-control" name="phonecode" style="width:61%; float:left; margin-bottom:15px;">
			                    <button type="button" class="btn btn-primary btn-primary" id="btnSendCode" style="float:left;margin-left:10px;">发送验证码</button>
			                    </div>
			                </div>
			                


                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit" id="doSubmit" style="margin-right:100px;">保存</button>
                                    <button type="reset" class="btn btn-default">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
    <script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>	
    <!-- iCheck -->
    <script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="__PUBLIC__/admin/js/common/ajax.js"></script>

<script>
    var addpaypwdUrl = "{:url('member/service')}";
    var addpaypwdcode = "{:url('SmsCode/send')}";

    var InterValObj; //timer变量，控制时间
    var count = {$messtime}; //间隔函数，1秒执行
    var curCount;//当前剩余秒数



    $(function(){
        $('#btnSendCode').click(function(){
            var new_phone = $('#new_phone').val();
            if(!new_phone){
                layer.msg('新客服手机号不能空', {icon: 2,time: 1000});
                return false;
            }
            $(this).attr("disabled", "true");
            layer.load(2);
            //向后台发送处理数据
            $.ajax({
                url:addpaypwdcode,
                type:'POST',
                data:{'type':5,'phone': new_phone},
                dataType:'json',
                success:function(data){
                    if(data.status == 1){
                        layer.closeAll('loading');
                        layer.msg(data.mess, {icon: 1,time: 1000});
                        curCount = count;
                        $("#btnSendCode").css({backgroundColor:'#f5f5f5',color:'#333'});
                        //设置button效果，开始计时
                        $("#btnSendCode").text("重发("+curCount+")s");
                        InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次
                    }else{
                        layer.closeAll('loading');
                        $("#btnSendCode").removeAttr("disabled");//启用按钮
                        layer.msg(data.mess, {icon: 2,time: 2000});
                    }
                },
                error:function(){
                    layer.closeAll('loading');
                    $("#btnSendCode").removeAttr("disabled");//启用按钮
                    layer.msg('操作失败，请重试', {icon: 2,time: 2000});
                }
            });
        });


        jQuery.validator.addMethod("pwd", function(value, element) {
            var tel = /^\d{6}$/;
            return this.optional(element) || (tel.test(value));
        }, "提现密码为6位数字组成");

        var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
        $('#form').validate({
            errorElement : 'span',
            debug: true,//只验证不提交表单
            //layer ajax提交表单
            submitHandler:function(){
                // 序列化 表单数据 后提交 ，太简洁了
                post(addpaypwdUrl,'POST',$('#form').serialize(),1);
                return false;
            },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法

            rules:{
                phonecode:{required:true},
                new_phone:{required:true},
            },

            messages:{
                phonecode:{required:icon+'必填'},
                new_phone:{required:icon+'必填'},
            }
        });
    });

    function cl(){
        location.reload();
    }

    //timer处理函数
    function SetRemainTime() {
        if (curCount == 0) {
            window.clearInterval(InterValObj);//停止计时器
            $("#btnSendCode").removeAttr("disabled");//启用按钮
            $("#btnSendCode").css({backgroundColor:'#1992FC',color:'#FFF'});
            $("#btnSendCode").text("重发");
        }
        else {
            curCount--;
            $("#btnSendCode").text("重发("+curCount+")s");
        }
    }

</script>


</body>
</html>
